/*
 * IC Project - a prototype to test a hypothesis of collective intelligence
 * Copyright (C) 2012 Paolo Conte - paolo@concavi.net
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * This code is derived from the project ojoverse (2008, same author)
 * under the license GPL2. See <http://www.gnu.org/licenses/>.
 */

package org.ix.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import javax.servlet.ServletContext;

public class ContextUtils {

    private static Properties properties = null;
    private static Properties messages = null;

    public ContextUtils(ServletContext context) {
        if (properties == null) {
            properties = new Properties();
            InputStream inputStream = context.getResourceAsStream(context.getInitParameter("properties"));
            try {
                properties.load(inputStream);
            } catch (IOException ioexc) {
                ioexc.printStackTrace();
            }
        }

        if (messages == null) {
            messages = new Properties();
            InputStream inputStream = context.getResourceAsStream(context.getInitParameter("messages"));
            try {
                messages.load(inputStream);
            } catch (IOException ioexc) {
                ioexc.printStackTrace();
            }
        }
    }

    public static String lbl(String key) {
        return messages.getProperty(key);
    }
    public static String prop(String key) {
        return properties.getProperty(key);
    }
}
